{% extends "main_card.html.twig" %}
{% macro genId(widget) %}{{ widget.vars.full_name }}{% endmacro %}

{% form_theme form "form/settings_form.html.twig" %}

{% block title %}{% trans %}settings.title{% endtrans %}{% endblock %}

{% block card_title %}<i class="fa-solid fa-gears fa-fw"></i> {% trans %}settings.title{% endtrans %}{% endblock %}

{% block card_content %}
    {{ form_start(form) }}

    {# Tabs #}
    <ul class="nav nav-tabs">
        {% for tab_widget in form %}
            {# Create a tab for each compound form #}
            {% if tab_widget.vars.compound ?? false %}
                <li class="nav-item">
                    <button type="button" class="nav-link {% if loop.first %}active{% endif %}" aria-current="page" data-bs-toggle="tab"
                            id="settings-{{ _self.genId(tab_widget) }}-tab" data-bs-target="#settings-{{ _self.genId(tab_widget) }}-pane"
                    >{{ (tab_widget.vars.label ?? tab_widget.vars.name|humanize)|trans }}</button>
                </li>
            {% endif %}
        {% endfor %}
    </ul>

    {# Panes #}
    <div class="tab-content">
        {% for tab_widget in form %}
            {# Create a tab for each compound form #}
            {% if tab_widget.vars.compound ?? false %}
                <div class="tab-pane fade pt-2 {% if loop.first %}show active{% endif %}" id="settings-{{ _self.genId(tab_widget) }}-pane">
                    {{ form_help(tab_widget) }}
                    {{ form_errors(tab_widget) }}

                    {% for section_widget in tab_widget %}
                        {% set settings_object = section_widget.vars.value %}

                        {% if section_widget.vars.embedded_settings_metadata is defined %} {# Check if we have nested embedded settings or not #}
                            <fieldset>
                                <legend class="offset-3">
                                    <i class="fa-solid {{ settings_icon(settings_object)|default('fa-sliders') }} fa-fw"></i>
                                    {{ (section_widget.vars.label ?? section_widget.vars.name|humanize)|trans }}
                                </legend>
                                <div class="row">
                                    <div class="offset-sm-3 col mb-3 ps-2">
                                        <b>{{ form_help(section_widget) }}</b>
                                        {{ form_errors(section_widget) }}
                                    </div>
                                </div>
                                {{ form_widget(section_widget) }}
                            </fieldset>
                            {% if not loop.last %}
                                <hr class="mx-0 mb-2 mt-2">
                            {% endif %}
                        {% else %} {# If not a compound render as normal row #}
                            {{ form_row(section_widget) }}
                        {% endif %}
                    {% endfor %}
                </div>
            {% endif %}
        {% endfor %}
    </div>

    {{ form_end(form) }}
{% endblock %}
